home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / geometry / transform3 / tm3perspfov.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-26  |  1.5 KB  |  57 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Pat Hanrahan, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #include <stdio.h>
  13. #include <math.h>
  14. #include "radians.h"
  15. #include "transform3.h"
  16. #include "ooglutil.h"    /* For OOGLError() */
  17.  
  18. /*
  19.  *
  20.  *     ( cot(fov/2)/aspect       0           0           0    )
  21.  *     (         0          cot(fov/2)       0           0    )
  22.  * T = (         0               0     -(f+n)/(f-n)     -1    )
  23.  *     (         0               0     -2*f*n/(f-n)      0    )
  24.  *
  25.  * Transform to the unit cube. Also flip from rh to lh.
  26.  */
  27. void
  28. Tm3PerspectiveFOV( T, fov, aspect, n, f )
  29.     Transform3 T;
  30.     float fov, aspect, n, f;
  31. {
  32.     float cotfov;
  33.  
  34.     Tm3Identity( T );
  35.  
  36.     if( n == f ) {
  37.     OOGLError(1/*UserError*/, "Tm3Perspective: n and f must be different" );
  38.     return;
  39.     }
  40.     if( fov == 0. ) {
  41.     OOGLError(1/*UserError*/, "Tm3Perspective: fov must not equal 0" );
  42.     return;
  43.     }
  44.  
  45.     cotfov = tan( RADIANS(fov)/2.0 );
  46.     if( cotfov != 0. )
  47.     cotfov = 1. / cotfov;
  48.  
  49.  
  50.     T[X][X] =  cotfov/aspect;
  51.     T[Y][Y] =  cotfov;
  52.     T[Z][Z] = -2*(f+n)/(f-n);
  53.     T[W][Z] = -2*f*n/(f-n);
  54.     T[X][W] = -1.;
  55.     T[W][W] =  0.;
  56. }
  57.